package com.xuzz.xrpc.spring.context;

import com.xuzz.xrpc.common.PropertyConfig;
import com.xuzz.xrpc.registry.RegistrarFactory;
import org.springframework.context.ApplicationContext;

/**
 * @description:
 * @author: xuzz
 * @create: 2020-02-22 18:03
 */
public class XPRCServerBootstrap {
    private static XPRCServerBootstrap instance;
    private ApplicationContext applicationContext;
    public static synchronized XPRCServerBootstrap getInstance() {
        if (instance == null) {
            instance = new XPRCServerBootstrap();
        }
        return instance;
    }

    public XPRCServerBootstrap setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
        return this;
    }

    public void start()
    {

        for(String name :applicationContext.getBeanNamesForType(ServiceBean.class))
        {
            ServiceBean bean = (ServiceBean)applicationContext.getBean(name);
            RegistrarFactory.getRegistrar().register(bean.getInterfaceName());
        }
    }
}
